<?php
/*
	Version   : 1.1
	Created   : 20080917
	Modified  : 20090927
	Author    : Pablo Larenas
	co-Author : Pablo Ramirez
	Descr     : Controlador "Surveyors"
	Changelog : 1.0 Version Inicial
				1.1 Control de Acceso
*/
class SurveyorsController extends AppController
{
	var $name       = 'Surveyors';
	var $helpers    = array('Html','Javascript','Ajax');
	//var $scaffold;
	
	function index() {
		$this->checkSession('admin');
		$this->layout = 'maintenance';
		
		if (empty($this->data)) {
		
		$surveyors = $this->Surveyor->findAll(null,'*','sur_codigo ASC');
			foreach($surveyors as $surveyor) {
				$temp = array();
				foreach($surveyor['Surveyor'] as $key=>$value) {
					$temp[$key] = $value;
				}
				$surveyorArray[] = $temp;
			}
			$this->set('surveyors', $surveyorArray);
		} 
	}
	
	function add($id = null) {
		$this->checkSession('admin');
		$this->layout = 'ajax';
		if (!empty($this->data)){
			if ($this->Surveyor->save($this->data)){
				$this->redirect('/surveyors'); 
			}
		} else {
			$this->set('id', $id);
		}
	}
	
	function edit($id = null) {
		$this->checkSession('admin');
		$this->layout = 'ajax';
		$this->Surveyor->id = $id;
		
		if (empty($this->data)){
			$this->data = $this->Surveyor->read();
			$this->set('id', $id);
		}else{
			if ($this->Surveyor->save($this->data)){
				$this->redirect('/surveyors'); 
				//$this->flash('Item Editado','/depots');
			} else {
				$this->Session->setFlash('Error al editar el Item');
			}
		}
	}
	
	function view($id = null) {
		$this->checkSession('admin');
		$this->layout = 'ajax';
		$this->Surveyor->id = $id;
		
		if (empty($this->data)){
			$this->data = $this->Surveyor->read();
			$this->set('id', $id);
		}
	}
	
	function delete($id) {
		$this->checkSession('admin');
		if ($this->Surveyor->del($id)) { 
			$this->set('error', '0');
		} else {
			$this->set('error','1');
		}
		$this->redirect('/surveyors');
	
	}
}
?>